var fs = require('fs');
var request = require('request');
var accessToken=require(process.cwd()+"/server/util/accessToken.js");

//token，因为token是存在文件里的所以这里进行文件读取得到token
var token = fs.readFileSync(accessToken.getAccessTokenPath(),'utf-8').toString();

//常用type为view和click,分别为点击事件和链接
var menus = {
  "button": [
    {
      "name": "测试菜单",
      "sub_button": [
        {
          "type": "view",
          "name": "授权登录",
          "url": "http://wuyrsp3tma.proxy.qqbrowser.cc/auth"
        }]
    }]
};

var options = {
    url: 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' + token,
    form: JSON.stringify(menus),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  };

module.exports.createMenu=function() {
  request.post(options, function (err, res, body) {
    if (err) {
      console.log(err)
    }else {
      console.log(body);
    }
  });  
};